package com.hgk.wanwan.chatactivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.common.handmark.pulltorefresh.library.PullToRefreshBase;
import com.common.handmark.pulltorefresh.library.PullToRefreshListView;
import com.common.handmark.pulltorefresh.library.internal.BallBaseAdapter;
import com.google.android.gms.common.api.GoogleApiClient;
import com.hgk.common.common.ui.activity.UpAndDownRefreshActivity;
import com.hgk.common.common.ui.view.RippleView;
import com.hgk.wanwan.chatactivity.adapter.ChatAdapter;
import com.hgk.wanwan.chatactivity.molde.ChatBean;
import com.hgk.wanwan.chatactivity.molde.MsgIfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import width.hgk.wanwan.R;

/*
* 失败！！！！！！！！
* */
public class ChatActivity extends UpAndDownRefreshActivity {

    private PullToRefreshListView mPtrlistView;
    private ChatAdapter adapter;
    private List<MsgIfo> mList;
    private RippleView mRvRight, mRvLeft;
    private EditText mEvContent;
    private String mContent;
    private ChatBean.Data data;
//    private ListView mListView;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_chat);
        mList = new ArrayList<MsgIfo>();
        initChatView();
        mPtrlistView = (PullToRefreshListView) findViewById(R.id.pull_refresh_chat_list);
        adapter = new ChatAdapter(mContext, mList);
        mPtrlistView.setAdapter(adapter);
    }

    private void initChatView() {

        mRvLeft = (RippleView) findViewById(R.id.ripv_btn_left);
        mRvRight = (RippleView) findViewById(R.id.ripv_btn_right);
        mEvContent = (EditText) findViewById(R.id.et_content_view_chat);
        mRvRight.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                mContent = mEvContent.getText().toString();
                adapter.addDataToAdapter(new MsgIfo(mContent, null,null));
                adapter.notifyDataSetChanged();
                mEvContent.setText("");
            }
        });
        mRvLeft.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                mContent = mEvContent.getText().toString();
                adapter.addDataToAdapter(new MsgIfo(null,mContent,null));
                adapter.notifyDataSetChanged();
                mEvContent.setText("");
            }
        });
    }


    @Override
    protected BallBaseAdapter getAdapte() {
        return null;
    }

    @Override
    protected PullToRefreshBase.Mode onCreate() {
        return null;
    }

    @Override
    protected void onDownRefresh() {

    }

    @Override
    protected void onUpRefresh() {

    }

    @Override
    protected Map getApiParams(String action) {
        return null;
    }

    @Override
    protected void success(String action, Object result) {

    }

    @Override
    protected void fail(String action, String failStr) {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    }

    @Override
    public void setLeftButton(RelativeLayout relativeLayout, Button button) {

    }

    @Override
    public void setRightButton(RelativeLayout relativeLayout, Button button) {

    }

    @Override
    public Object getTitleString() {
        //以后可以改为对话的人昵称
        return "聊天界面";
    }

    public static void launch(Context context) {
        context.startActivity(new Intent(context, ChatActivity.class));
    }
}
